package ukoly;

import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import uzivatele.Uzivatel;

/**
 * Model pro ukoly ve Spravci Ukolu
 * 
 * @author Pavel Lieberzeit
 */
public class UkolModel {

    final private int ID;
    private String jmeno;
    private String popis;
    
    private GregorianCalendar casStart;
    
    private GregorianCalendar casKonec;
    
    private GregorianCalendar casDead; //deadline
    
    private ArrayList <Komentar> komentare; 
    
    private int casStraven; //should be in hours
    
    private Uzivatel vlastnik; 
    
    private ProjektControl projekt; 
    
    private UkolStatus status;
    
//    private ArrayList <TimelinePrvek> timeline;

    
    /**
     * Pro vytvoreni noveho ukolu
     * @param ID
     * @param jmeno
     * @param popis
     * @param deadline
     * @param projekt
     * @param vlastnik
     * @param status 
     */
    public UkolModel(int ID, String jmeno, String popis, GregorianCalendar deadline, ProjektControl projekt,
            Uzivatel vlastnik, UkolStatus status, int casStraven) {
        this(ID, jmeno, popis, new GregorianCalendar(), null, deadline, projekt, vlastnik, status, 
                new ArrayList<Komentar>(), casStraven);
        
        this.casStart.setTime(new Date(System.currentTimeMillis()));
                
    }
    
    /**
     * Konstruktor pro parametry nize. GregorianCalendar slouzi pro deadline. Pro vytvoreni z databaze
     * @param ID
     * @param jmeno
     * @param popis
     * @param deadline
     * @param projekt
     * @param vlastnik
     * @param status
     */
    public UkolModel(int ID, String jmeno, String popis, GregorianCalendar casStart, GregorianCalendar casKonec,
            GregorianCalendar deadline, ProjektControl projekt, Uzivatel vlastnik, UkolStatus status, ArrayList<Komentar> komentare,
            int casStraven) {
        this.ID = ID;
        this.jmeno = jmeno;
        this.popis = popis;
        
        this.casDead = deadline;
        this.casStart = casStart;
        this.casKonec = casKonec;
        
        if(komentare == null)
            this.komentare = new ArrayList<Komentar>();
        else
            this.komentare = komentare;
        
        
        this.casStraven = casStraven;
        
        this.projekt = projekt;
        this.vlastnik = vlastnik;
        this.status = status;
        
    }

    public void setCasKonec(GregorianCalendar casKonec) {
        this.casKonec = casKonec;
    }

    public GregorianCalendar getCasDead() {
        return casDead;
    }

    public void setCasDead(GregorianCalendar casDead) {
        this.casDead = casDead;
    }

    public int getCasStraven() {
        return casStraven;
    }

    public void setCasStraven(int casStraven) {
        this.casStraven = casStraven;
    }

    public String getJmeno() {
        return jmeno;
    }

    public void setJmeno(String jmeno) {
        this.jmeno = jmeno;
    }

    public String getPopis() {
        return popis;
    }

    public void setPopis(String popis) {
        this.popis = popis;
    }


    public ProjektControl getProjekt() {
        return projekt;
    }

    public void setProjekt(ProjektControl projekt) {
        this.projekt = projekt;
    }


    public Uzivatel getVlastnik() {
        return vlastnik;
    }

    public void setVlastnik(Uzivatel vlastnik) {
        this.vlastnik = vlastnik;
    }

    public UkolStatus getStatus() {
        return status;
    }

    public void setStatus(UkolStatus status) {
        this.status = status;
    }

    public int getID() {
        return this.ID;
    }

    public GregorianCalendar getCasKonec() {
        return casKonec;
    }

    public GregorianCalendar getCasStart() {
        return casStart;
    }

   
    public ArrayList <Komentar> getKomentare() {
        return komentare;
    }

//    public ArrayList<TimelinePrvek> getTimeline() {
//        return timeline;
//    }

    
    /**
     * Technicka poznamka - v praktickem vyuziti by se equals nemelo skoro pouzit, protoze
     * jediny rozpoznavaci atribut je ID. Udaje se uvnitr programu neukladaji a posilaji/nacitaji se do databaze
     * Equals doesn't include times, sadly - too little time
     * Not uzivatel either, because of loops
     * TODO look up here
     * @param obj
     * @return 
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final UkolModel other = (UkolModel) obj;
        if (this.ID != other.ID) {
            return false;
        }
        if ((this.jmeno == null) ? (other.jmeno != null) : !this.jmeno.equals(other.jmeno)) {
            return false;
        }
        if ((this.popis == null) ? (other.popis != null) : !this.popis.equals(other.popis)) {
            return false;
        }
        if (this.casStraven != other.casStraven) {
            return false;
        }
        if (this.status != other.status) {
            return false;
        }
        return true;
    }

    
    /**
     * some explanation in equals
     * @return 
     */
    @Override
    public int hashCode() {
        int hash = 7;
        hash = 61 * hash + this.ID;
        hash = 61 * hash + (this.jmeno != null ? this.jmeno.hashCode() : 0);
        hash = 61 * hash + (this.popis != null ? this.popis.hashCode() : 0);
        hash = 61 * hash + this.casStraven;
        hash = 61 * hash + (this.status != null ? this.status.hashCode() : 0);
        return hash;
    }
    
    
    
    
    
}
